/*
 * 功能：投诉职位
 * 依赖：jQuery1.4以上
 * 制作：lesanc.li
 * 日期: 2011-11-14
 */
function showTanK(mm){
	var h1=window.screen.height;
	var h2=document.body.scrollHeight;
	var h3;
	var topd;
	if(h1<h2){h3=h2}else{h3=h1}
	if(document.documentElement && document.documentElement.scrollTop){ 
		topd=document.documentElement.scrollTop; 
	}else if(document.body && document.body.scrollTop){ 
		topd=document.body.scrollTop;
	}else{topd=0}
	$("#song1104_cheng").css("top",topd+"px");
	$("#song1104_kang").css("top",topd+"px");
	$("#song_dakang").css("height", h3 + "px").show();
	$("#" + mm).show();
  $("textarea[name=\"advice\"]").bind("click", function(){
    inputLimit($(this), 1000);
  });
}
function closeTanK(nn){
   $("#" + nn).hide();
   $("#song_dakang").hide();
	 setCookie("tankSub", "");
   $("div.song1104_err").hide();
   $("div.limitwords").html("还可以输入1000字").removeClass("song1104_err").hide();
}
//文本框输入字数提示
function inputLimit(el, n, vtype){
  var editPanel = $(el).parents("form");
  var limitDiv = $(el).next('.limitwords');
  limitDiv.removeClass("song1104_err").show();
  vtype = vtype || "val";
  var elLen = 0;
  $(el).bind("blur", function(){clearInterval(timeId);});
  var timeId = setInterval(function(){
    elLen = (vtype == "val")?$(el).val().length:$(el).text().length;
    if (elLen > n){
      limitDiv.html('<span style="color:red">已超过' + (elLen - n) + '字</span>').addClass("song1104_err");
    }else{
      limitDiv.html('还可以输入' + (n - elLen) + '字').removeClass("song1104_err");
    }
  }, 500);
  $(el).bind("keypress", function(event){
    event = event || window.event;
    elLen = (vtype == "val")?$(el).val().length:$(el).text().length;
    if (elLen >= n && event.keyCode != 8){
      return false;
    }
  });
  $(el).bind("paste", function(e){
    setTimeout(function(){
      if (vtype == "val"){
        $(el).val($.trim($(el).val().replace(/\s+/g, " ")).substring(0, n));
      } else {
        $(el).html($.trim($(el).text().replace(/\s+/g, " ")).substring(0, n));
      }
      setTimeout(function(){
        elLen = (vtype == "val")?$(el).val().length:$(el).text().length;
        if (elLen > n){
          limitDiv.html('<span style="color:red">已超过' + (elLen - n) + '字</span>').addClass("song1104_err");
        } else {
          limitDiv.html('还可以输入' + (n - elLen) + '字').removeClass("song1104_err");
        }
      }, 500);
    }, 500);
  });
}
function decodeStr(s){
	if(decodeURIComponent){return decodeURIComponent(s);
  }else{return unescape(s);}
}
function getTanK(that,job,job_company,name,email,phone,job_url,zpuserid,aid){
  var song1104_form = document.forms["song1104_form"];
	$("#song1104_job").html(((decodeStr(job).length > 20)?decodeStr(job).substring(0,20)+"...":decodeStr(job)) || "");
	song1104_form.job.value = decodeStr(job) || "";
	$("#song1104_job_company").html(((decodeStr(job_company).length > 22)?decodeStr(job_company).substring(0,22)+"...":decodeStr(job_company)) || "");
	song1104_form.job_company.value = decodeStr(job_company) || "";
	song1104_form.zpuserid.value = zpuserid || "";
	song1104_form.job_url.value = decodeStr(job_url) || "";
	song1104_form.aid.value = aid || "";
	song1104_form.name.value = decodeStr(name) || "";
	song1104_form.phone.value = phone || "";
	song1104_form.email.value = decodeStr(email) || "";
	song1104_form.cmbType1.checked = false;
	//song1104_form.cmbType2.checked = false;
	song1104_form.cmbType3.checked = false;
	song1104_form.cmbType4.checked = false;
	song1104_form.advice.value = "最多可以输入1000字";
  song1104_form.advice.style.color="#999999";
	showTanK('song1104_kang');
}
function isEmail(s){
  if (s.length > 200) {
      return false;
  }
  s = s.toLowerCase();
  var strSuffix = "cc|com|edu|gov|int|net|org|biz|info|pro|name|coop|al|dz|af|ar|ae|aw|om|az|eg|et|ie|ee|ad|ao|ai|ag|at|au|mo|bb|pg|bs|pk|py|ps|bh|pa|br|by|bm|bg|mp|bj|be|is|pr|ba|pl|bo|bz|bw|bt|bf|bi|bv|kp|gq|dk|de|tl|tp|tg|dm|do|ru|ec|er|fr|fo|pf|gf|tf|va|ph|fj|fi|cv|fk|gm|cg|cd|co|cr|gg|gd|gl|ge|cu|gp|gu|gy|kz|ht|kr|nl|an|hm|hn|ki|dj|kg|gn|gw|ca|gh|ga|kh|cz|zw|cm|qa|ky|km|ci|kw|cc|hr|ke|ck|lv|ls|la|lb|lt|lr|ly|li|re|lu|rw|ro|mg|im|mv|mt|mw|my|ml|mk|mh|mq|yt|mu|mr|us|um|as|vi|mn|ms|bd|pe|fm|mm|md|ma|mc|mz|mx|nr|np|ni|ne|ng|nu|no|nf|na|za|aq|gs|eu|pw|pn|pt|jp|se|ch|sv|ws|yu|sl|sn|cy|sc|sa|cx|st|sh|kn|lc|sm|pm|vc|lk|sk|si|sj|sz|sd|sr|sb|so|tj|tw|th|tz|to|tc|tt|tn|tv|tr|tm|tk|wf|vu|gt|ve|bn|ug|ua|uy|uz|es|eh|gr|hk|sg|nc|nz|hu|sy|jm|am|ac|ye|iq|ir|il|it|in|id|uk|vg|io|jo|vn|zm|je|td|gi|cl|cf|cn"
  var regu = "^[a-z0-9][_a-z0-9\-]*([\.][_a-z0-9\-]+)*@([a-z0-9\-\_]+[\.])+(" + strSuffix + ")$";
  var re = new RegExp(regu);
  if (s.search(re) != -1) {
    return true;
  } else {
    return false;
  }
}
function submitTank(){
  var song1104_form = document.forms["song1104_form"];
	if(!song1104_form.cmbType1.checked && !song1104_form.cmbType3.checked && !song1104_form.cmbType4.checked){
		$("#cmbType_err").show();
		song1104_form.cmbType1.onclick = song1104_form.cmbType3.onclick = song1104_form.cmbType4.onclick = function(){
			$("#cmbType_err").hide();
		}
		return false;
	}
	if(song1104_form.advice.value == "" || song1104_form.advice.value == "最多可以输入1000字"){
	  $("#advice_err").html("请填写投诉说明").addClass("song1104_err").show();
		return false;
	}else if(song1104_form.advice.value.length > 1000){
		return false;
	}
	if(song1104_form.name.value == ""){
	  $("#name_err").show();
		song1104_form.name.onclick = function(){
			$("#name_err").hide();
		}
		return false;
	}
	if(song1104_form.email.value == ""){
	  $("#email_err").html("请填写邮箱").show();
		song1104_form.email.onclick = function(){
			$("#email_err").hide();
		}
		return false;
	}else if(!isEmail(song1104_form.email.value)){
    $("#email_err").html("您输入的邮箱格式不正确。").show();
		song1104_form.email.onclick = function(){
			$("#email_err").hide();
		}
		return false;		
	}
	if(song1104_form.phone.value == ""){
	  $("#phone_err").html("请填写联系电话").show();
		song1104_form.phone.onclick = function(){
			$("#phone_err").hide();
		}
		return false;
	} else if (strlen(song1104_form.phone.value)>30){
    $("#phone_err").html("您已超过规定的字符限制，请调整。").show();
		song1104_form.phone.onclick = function(){
			$("#phone_err").hide();
		}
		return false;
  }
	setCookie("tankSub", "ok");
  song1104_form.submit();
}
function isChinese(str)
{
   var lst = /[u00-uFF]/;      
   return !lst.test(str);     
}
function strlen(str)
{
   var strlength=0;
   for (i=0;i<str.length;i++)
  {
     if (isChinese(str.charAt(i))==true)
        strlength=strlength + 2;
     else
        strlength=strlength + 1;
  }
return strlength;
}
function getCookie(name){
	var s = document.cookie.indexOf(name + '=');
	if (s > -1) {
			var l = document.cookie.indexOf(";", s);
			if (l < 0) l = document.cookie.length;
			var itemValue = document.cookie.substring(s + new String(name + '=').indexOf('=') + 1, l);
			return decodeURIComponent(itemValue);
	}
	return '';
}
function setCookie(name, value, expires, path, domain, secure){
	document.cookie= name + '=' + escape(value) +
	((expires) ? '; expires=' + expires.toGMTString() : '') +
	((path) ? '; path=' + path : '') +
	((domain) ? '; domain=' + domain : '') +
	((secure) ? '; secure' : '');
}
var cbValue = (/cbvalue=(\d)/i.test(location.search))?RegExp['$1']:2;
var song1104_result = $("#song1104_result");
var tankSub = (navigator.cookieEnabled)?getCookie("tankSub"):"ok";
if(cbValue == 1 && tankSub == "ok"){
  song1104_result.html("您的投诉申请已提交，我们会尽快处理，感谢您对我们工作的支持！");
  showTanK('song1104_cheng');
}else if(cbValue == 0 && tankSub == "ok"){
  song1104_result.html("申请提交不成功，请重新提交。");
  showTanK('song1104_cheng');
}else if(cbValue == 2 && tankSub == "ok"){
  song1104_result.html("抱歉，您每天投诉的职位不能超过5个");
  showTanK('song1104_cheng');
}
var adviceObj = document.forms["song1104_form"].advice;
adviceObj.onfocus=function(){
  if(this.value=='最多可以输入1000字'){
    this.value='';
    this.style.color="#000000";
  }
};
adviceObj.onblur=function(){
  if(this.value==''){
    this.value='最多可以输入1000字';
    this.style.color="#999999";
  }
};